#!usr/bin/env python  
# -*- coding:utf-8 -*-
""" 
@author:robot
@file: max_min_depth_bfs.py 
@version:
@time: 2024/01/27 
"""
from collections import deque


def min_depth_bfs(root):
    if not root:
        return 0
    queue = deque([(1, root)])

    while queue:
        depth, node = queue.popleft()

        if node and not node.left and not node.right:
            return depth
        if node:
            queue.append((depth + 1, node.left))
            queue.append((depth + 1, node.right))


def max_depth_bfs(root):
    if not root:
        return 0

    queue = deque([root])
    ans = 0
    while queue:
        tmp = []
        while queue:
            node = queue.popleft()
            if node.left:
                tmp.append(node.left)
            if node.right:
                tmp.append(node.right)
        ans += 1
        queue.extend(tmp)
    return ans
